/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaActualizarUsuario.java
 *
 * Created on 02-jun-2012, 12:51:18
 */
package edu.eam.gruposenior.gestorLEcciones.vista;

import javax.swing.JOptionPane;

import edu.eam.gruposenior.gestorLEcciones.controladores.UsuarioController;
import edu.eam.gruposenior.gestorLEcciones.entidades.Usuario;
import edu.eam.gruposenior.gestorLEcciones.util.LogginManager;

/**
 * 
 * @author Claudia
 */
public class VentanaActualizarUsuario extends javax.swing.JFrame {

	private Usuario user;

	/** Creates new form VentanaActualizarUsuario */
	public VentanaActualizarUsuario() {
		initComponents();
		user = LogginManager.getUsuario();
		tfCedula.setText(user.getCedula());
		tfNick.setText(user.getNickname());
		tfNombreCom.setText(user.getNombreCompleto());
		tfTel.setText(user.getTelefono());
		tfPassword.setText(user.getPassword());
		tfConPass.setText(user.getPassword());
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		tfNombreCom = new javax.swing.JTextField();
		jLabel4 = new javax.swing.JLabel();
		tfTel = new javax.swing.JTextField();
		jLabel3 = new javax.swing.JLabel();
		jLabel1 = new javax.swing.JLabel();
		jLabel5 = new javax.swing.JLabel();
		bEditar = new javax.swing.JButton();
		tfCedula = new javax.swing.JTextField();
		jLabel2 = new javax.swing.JLabel();
		tfConPass = new javax.swing.JPasswordField();
		tfNick = new javax.swing.JTextField();
		jLabel6 = new javax.swing.JLabel();
		tfPassword = new javax.swing.JPasswordField();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		jLabel4.setText("NickName");

		jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		jLabel3.setText("Telefono");

		jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		jLabel1.setText("Cedula");

		jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		jLabel5.setText("Password");

		bEditar.setIcon(new javax.swing.ImageIcon(
				getClass()
						.getResource(
								"/edu/eam/gruposenior/gestorLEcciones/vista/imagenes/Notepad.png"))); // NOI18N
		bEditar.setText("Editar");
		bEditar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				bEditarActionPerformed(evt);
			}
		});

		jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		jLabel2.setText("Nombre Completo");

		jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		jLabel6.setText("Confirmacion Password");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(55, 55, 55)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.TRAILING,
												false)
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabel5)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addComponent(
																		tfPassword,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		311,
																		javax.swing.GroupLayout.PREFERRED_SIZE))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabel4)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addComponent(
																		tfNick,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		311,
																		javax.swing.GroupLayout.PREFERRED_SIZE))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabel3)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addComponent(
																		tfTel,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		311,
																		javax.swing.GroupLayout.PREFERRED_SIZE))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabel1)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addComponent(
																		tfCedula,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		311,
																		javax.swing.GroupLayout.PREFERRED_SIZE))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabel2)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addComponent(
																		tfNombreCom,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		311,
																		javax.swing.GroupLayout.PREFERRED_SIZE))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabel6)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addComponent(
																		tfConPass,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		311,
																		javax.swing.GroupLayout.PREFERRED_SIZE)))
								.addContainerGap(66, Short.MAX_VALUE))
				.addGroup(
						javax.swing.GroupLayout.Alignment.TRAILING,
						layout.createSequentialGroup()
								.addContainerGap(274, Short.MAX_VALUE)
								.addComponent(bEditar).addGap(184, 184, 184)));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(47, 47, 47)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														tfCedula,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabel1))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														tfNombreCom,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabel2))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														tfTel,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabel3))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														tfNick,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabel4))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														tfPassword,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabel5))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														tfConPass,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabel6))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
								.addComponent(bEditar)
								.addContainerGap(28, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void bEditarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_bEditarActionPerformed
		String pass = new String(tfPassword.getPassword());
		String passCon = new String(tfConPass.getPassword());
		if (pass.equals(passCon)) {

			try {

				if (!tfCedula.getText().equals("")
						&& !tfNick.getText().equals("")
						&& !tfNombreCom.getText().equals("")
						&& !pass.equals("") && !tfTel.getText().equals("")
						&& !passCon.equals("")) {

					new UsuarioController().editarUsuario(tfCedula.getText(),
							true, tfNick.getText(), tfNombreCom.getText(),
							pass, tfTel.getText());

					JOptionPane.showMessageDialog(null,
							"Usuario editado con exito");
				} else {
					JOptionPane.showMessageDialog(null,
							"Hay campos que no tienen valor", "Campos vacios",
							JOptionPane.ERROR_MESSAGE);
				}

			} catch (Exception e) {
				JOptionPane.showMessageDialog(null, e.getMessage(),
						"Usuario no Encontrado", JOptionPane.ERROR_MESSAGE);
			}

		} else {
			JOptionPane.showMessageDialog(null, "El password no coincide",
					"Password Incorrecto", JOptionPane.ERROR_MESSAGE);
		}
	}// GEN-LAST:event_bEditarActionPerformed

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				new VentanaActualizarUsuario().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton bEditar;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JTextField tfCedula;
	private javax.swing.JPasswordField tfConPass;
	private javax.swing.JTextField tfNick;
	private javax.swing.JTextField tfNombreCom;
	private javax.swing.JPasswordField tfPassword;
	private javax.swing.JTextField tfTel;
	// End of variables declaration//GEN-END:variables
}
